﻿var parentWidth = 0;
var tabsWidth=0;

$(function() {
	
    //初始化布局
	var topMenuBarObj = $("#topMenuBar");
	var toLeftObj = $("#toLeft");
    var toRightObj = $("#toRight");
    
    toLeftObj.click(function(){
    	MoveAddressbar(topMenuBarObj, 50, "");
    })
    toRightObj.click(function(){
    	MoveAddressbar(topMenuBarObj, -50, "");
    })
    
    
    parentWidth=parseInt(topMenuBarObj.css("width"));
    topMenuBarObj.children().each(function(index, obj) {
    	
    	var jObj=$(obj);
        var marginRight = parseInt(jObj.css("margin-right"));
        var marginLeft = parseInt(jObj.css("margin-left"));
        
        var newWidth=parseInt(jObj.width())+1;
    	currentWidth = newWidth + marginRight + marginLeft+1;
    	tabsWidth += currentWidth;	
    	
    	jObj.width(newWidth);
    });
    topMenuBarObj.width(tabsWidth);
    
    //tab页少就隐藏左右按钮
    if(tabsWidth < $("#topBannerRight").width())
    {
    	toLeftObj.css("display","none");
    	toRightObj.css("display","none");
    }
       
    
    
	//初始化事件
	$(".topButton1, .topButton2").click(function(){
		
		var currentObj = $(this);
		
		if(currentObj.hasClass("topButton2"))
		{
			var parentObj=currentObj.parent();
			parentObj.children().each(function(index, obj) {
				
				var item=$(obj);
				
				if(currentObj[0].id==obj.id)
				{
					item.removeClass("topButton2");
					item.addClass("topButton1");
				}
				else
				{
					item.removeClass("topButton1");
					item.addClass("topButton2");
				}
				
			});
		}

		
	})
	
    
});

function MoveAddressbar(obj, moveValue, code) {
	var left = parseInt(obj.css("left"));
	
	if (moveValue > 0) {
        var newLeft = left + moveValue;
        if (newLeft > 0) {
            newLeft = 0;
        }
        obj.css("left",newLeft.toString() + "px");
    }
	else if (moveValue < 0) {
        var newLeft = left + moveValue;
        if (newLeft < parentWidth - tabsWidth) {
            newLeft = parentWidth - tabsWidth;
        }
        obj.css("left",newLeft.toString() + "px");
    }
}


